package com.example.excel;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.List;

/***
 * @class_name TestCountller
 * @description TODO: 
 * @author 李兵
 * @date 2019/6/7 10:48
 * @version V1.0
 */
@RestController
@RequestMapping("/test")
@Api(tags = "Excel上传下")
public class TestController {

    @Autowired
    ExportExceUtil exportExceUtil;
    @Autowired
    ImportExceUtil importExceUtil;

    /**
     * @description TODO:
     * @author 李兵
     * @date 2019/6/7 13:07
     * @Param [file:多文件, ispp：是否为平铺数据]
     * @Return boolean
     **/
    @RequestMapping(value = "/impexcel", method = RequestMethod.POST)
    public String impexcel(@RequestParam("file") MultipartFile file, @NotNull @RequestParam("ispp") Boolean ispp) {
        try {
            List list;
            if (ispp) {
                list = importExceUtil.impExcelFileByFlat(null, file.getInputStream(), 2, 0);
            } else {
                list = importExceUtil.impExcelFileByFixedFormat(null, file.getInputStream(), 5,2);
            }
            System.out.println(list.size());

            return list.get(0).toString();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    @RequestMapping(value = "/expexcel", method = RequestMethod.POST)
    public boolean expexcel() {
        return false;
    }
}
